package fnic.prehand.esagent.passitive_measure2;

import java.util.Calendar;

import org.apache.commons.pool2.BasePooledObjectFactory;
import org.apache.commons.pool2.PooledObject;
import org.apache.commons.pool2.impl.DefaultPooledObject;

import fnic.prehand.common.AgentConfig;

public class PoolAgentFactory
    extends BasePooledObjectFactory<PassitiveAgent> {

	private static final AgentConfig config = AgentConfig.getInstance();
	private static final int indexNumPerDay = config.getPaggr_interval();
	
    @Override
    public PassitiveAgent create() {
		Calendar ca = Calendar.getInstance();
	    int year = ca.get(Calendar.YEAR);//获取年份
	    int month=ca.get(Calendar.MONTH)+1;//获取月份 
	    int day=ca.get(Calendar.DATE);//获取日
//	    String indexName=year+"-"+month+"-"+day;
		int hour = ca.get(Calendar.HOUR_OF_DAY);// 获取小时
		String indexName = year+"-"+month+"-"+day+"_"+hour/indexNumPerDay;
        return new PassitiveAgent(indexName, config.getPesIndexType());
    }

    /**
     * Use the default PooledObject implementation.
     */
    @Override
    public PooledObject<PassitiveAgent> wrap(PassitiveAgent agent) {
        return new DefaultPooledObject<PassitiveAgent>(agent);
    }

    /**
     * When an object is returned to the pool, clear the buffer.
     */
/*    @Override
    public void passivateObject(PooledObject<PassitiveAgent> pooledObject) {
        pooledObject.getObject().setLength(0);
    }*/

    // for all other methods, the no-op implementation
    // in BasePooledObjectFactory will suffice
}
